<%@page import="Entity.User"%>
<%@page import="JavaServlet.TimeServlet.Student"%>
<%@page import="Entity.PageBeanStudent"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="bootstrap-3.3.7-dist/css/bootstrap.css"/>
<title>Insert title here</title>
<script src="js/jquery-1.11.3.js" type="text/javascript" charset="utf-8"></script>
<script src="js/layer/layer/layer.js" type="text/javascript" charset="utf-8"></script>
<script src="js/layer/layer/mylayer.js" type="text/javascript" charset="utf-8"></script>
<script src="js/layer/layer/util.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
	<form action="${pageContext.request.contextPath}/student?method=searchName" method="post">
		名字:<input type="text" name="searchName"/>
		<input type="submit" value="搜索"/>
	</form>
	<button class="btn btn-success" onclick="insert()">添加</button>
<!-- 	<a href="/JavaWeb190703/student_insert.jsp" class="btn btn-success">添加</a> -->
	<a href="${pageContext.request.contextPath}/online_user_list.jsp" class="btn btn-success">在线用户列表</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	欢迎归来：${user.name}
	<button class="btn btn-success" onclick="logout()" >注销</button>
<%-- 	<a href="${pageContext.request.contextPath}/loginServlet?method=logout" onclick="logout">注销</a> --%>
	<table class="table table-striped table-bordered table-hover table-condensed">
		<tr>
			<td>ID</td>
			<td>名字</td>
			<td>年龄</td>
			<td>性别</td>
			<td>删除</td>
			<td>修改</td>
		</tr>
		<c:forEach items="${pageBeanStudent.list}" var="student">
			<tr>
					<td>${student.id}</td>
					<td>${student.name}</td>
					<td>${student.age}</td>
					<td>${student.gender}</td>
					<td><a href="javascript:void(0)" onclick="deleteById(${student.id})" class="btn btn-danger">删除</a></td>
					<td><button onclick="update(${student.id})" class="btn btn-info">修改</button></td>
				</tr>
		</c:forEach>
	</table>
	<nav aria-label="Page navigation">
	  <ul class="pagination">
	     <!-- 上一页开始 -->
	     <c:if test="${pageBeanStudent.pageNo==1}">
	     	<li class="disabled">
	      	   <a href="#" aria-label="Previous">
		        <span aria-hidden="true">&laquo;</span>
		       </a>
		     </li>
	     </c:if>
	      <c:if test="${pageBeanStudent.pageNo!=1}">
	      	<li>
		      <a href="${pageContext.request.contextPath}/student?method=pageList&pageNo=${pageBeanStudent.pageNo-1}" aria-label="Previous">
		        <span aria-hidden="true">&laquo;</span>
		      </a>
		    </li>
	      </c:if>
	       <!-- 上一页结束-->
	      
	     <c:forEach begin="1" end="${ pageBeanStudent.totalPage}" var="i">
	     	<c:if test="${pageBeanStudent.pageNo==i }">
	     		<li class="active"><a href="#">${i}</a></li>
	     	</c:if>
	     	<c:if test="${pageBeanStudent.pageNo!=i }">
	     		<li><a href="${pageContext.request.contextPath}/student?method=pageList&pageNo=${i}">${i}</a></li>
	     	</c:if>
	     </c:forEach> 
	     <c:if test="${pageBeanStudent.pageNo==pageBeanStudent.totalPage}">
		      <li class="disabled">
		      <a href="#" aria-label="Next">
		        <span aria-hidden="true">&raquo;</span>
		      </a>
		    </li>
	     </c:if>
	     <c:if test="${pageBeanStudent.pageNo!=pageBeanStudent.totalPage }">	
		     <li>
		      <a href="${pageContext.request.contextPath}/student?method=pageList&pageNo=${pageBeanStudent.pageNo+1}" aria-label="Next">
		        <span aria-hidden="true">&raquo;</span>
		      </a>
		    </li>
	     </c:if>  
	  </ul>
	</nav>
	<script type="text/javascript">
		function deleteById(id) {
			layer.confirm(
				"您确认要删除么？",
// 				{icon:3},		
				function(index){
<%-- 					location.href = "<%=request.getContextPath()%>/student?method=deleteById&id=" + id; --%>
					console.log(index);
					$.post(
						"${pageContext.request.contextPath}/student?method=deleteById&id=" + id,
						function(jsonObj){
							if(jsonObj.code == util.SUCCESS){
								mylayer.successMsg(jsonObj.msg);
								location.reload();
							}else{
								mylayer.errorMsg(jsonObj.msg);
							}
						},
						"json"
					);
				}
			);
		}
		function logout(){
			layer.confirm(
				"您确认要注销吗？",
				{icon:3},
				function(index){
					location.href="${pageContext.request.contextPath}/loginServlet?method=logout" ;
					layer.close(index);
				}
			);
		}
		function insert(){
			layer.open({
		     	type:2,
		     	title : "添加学生",
		     	btn:["关闭"],
		     	area:["500px","300px"],
		     	content:"${pageContext.request.contextPath}/student?method=chooseBanji"
// 		     	shadeClose:true,
// 		     	yes:function(index,layero){
// 		     		layer.close(index);
// 		     	},
		    });
		}
		function update(id){
			layer.open({
		     	type:2,
		     	btn:["关闭"],
		     	content:"${pageContext.request.contextPath}/student?method=toUpdate&id=" + id,
		     	area:["500px","300px"]
// 		     	shadeClose:true,
// 		     	yes:function(index,layero){
// 		     		layer.close(index);
// 		     	},
		    });
		}
	</script>   
</body>
</html>